<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ApplicationRecord extends Model
{
    use HasFactory;

    protected $fillable = ['application_id','reviewer_id','level','status','comment','is_process'];

    const POSTONLY = ['application_id','reviewer_id','level','status','comment','is_process'];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    protected $appends = [
        'status_text'
    ];

    public function getStatusTextAttribute()
    {
        $arr = ['pending'=>'待审核','approved'=>'已通过','rejected'=>'已驳回'];
        return $arr[$this->status];
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','reviewer_id')->select('id','name');
    }

    public function role()
    {
        return $this->hasOne(Role::class,'id','role_id')->select('id','name');
    }

    public function application()
    {
        return $this->hasOne(Application::class,'id','application_id')->select('id','model','source');
    }
}
